%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
% Main File
% Date: August 2014 / August 2017
% Author: Nitya / Aaron
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55

%%%%%%%%%%%%%%%%%
%BASELINE DATASETS WERE:
%1.sample_static_jpn_nsU_update.txt
%2. sample_static_nonjpn_nsU_update.txt
%3. sample_static_nonmult_nsU_update.txt
%4. sample_static_all_nsU_update.txt
%5. sample_static_jpn_auto_nsU_update.txt
%6. sample_static_jpn_nonauto_nsU_update.txt
%7. sample_static_all_auto_nsU_update.txt
%8. sample_static_all_nonauto_nsU_update.txt
%%%%%%%%%%%%%%%%%%


clear all
clc
cd 'dir'

diary on
global sample_est nu_i mu
sample = csvread('sample_static_all_nsU_update_diff.txt');
sample_est=sample;
size(sample)


om0  = 0.3;
psi0 = 0.3;

startval = [om0 psi0]; 
theta = fminsearch('est_obj_scale',startval);

disp('Actual Point Estimates')
disp(theta)

disp('Mean nu_i')
disp(mean(nu_i))

disp('Std Deviation nu_i')
disp(std(nu_i))

disp('Mean mu')
disp(mean(mu))

disp('Std mu')
disp(std(mu))

%disp('Mean mu')
%disp(mean(mu))

%Bootstrap


N_sample = size(sample,1)


rand('seed',1234);


N = xxxx;
theta_bs = zeros(N,2);
nu_info_bs= zeros(N,2);
draws = zeros(N_sample,1);
fval=0;
exitflag=0;
%mu0 = 0.5;
om0 = 0.3;
psi0 = 0.3;
tries=1; %number of bootstraps done

startval = [om0 psi0];

while tries <=N
	%sample_bs = zeros(size(sample));
	draws=ceil(N_sample*rand(N_sample,1));
	sample_est=sample(draws,:);

[temp, fval, exitflag] = fminsearch('est_obj_scale',startval);

	if exitflag==1 & 0 <= temp(1) & 0 <= temp(2) & temp(1) <= 2 & temp(2) <= 2
		theta_bs(tries,:)=temp;
		tries=tries+1;
		nu_info_bs(tries,:)=[mean(nu_i) std(nu_i)];
	end


end

theta_bs

disp('Bootstrap Std Dev')
disp(std(theta_bs))

disp('Std Deviation of Bootstrap Means and Std Dev of BS std deviations')
disp(std(nu_info_bs))

disp('97.5 Percentile')
prctile(theta_bs(:,1),97.5)

disp('2.5 Percentile')
prctile(theta_bs(:,1),2.5)

disp('95 Percentile')
prctile(theta_bs(:,1),95)

disp('5 Percentile')
prctile(theta_bs(:,1),5)

disp('97.5 Percentile')
prctile(theta_bs(:,2),97.5)

disp('2.5 Percentile')
prctile(theta_bs(:,2),2.5)

disp('95 Percentile')
prctile(theta_bs(:,2),95)

disp('5 Percentile')
prctile(theta_bs(:,2),5)
	